/*
 * @Description:
 * @Version: 2.0
 * @Autor: wangmiao
 * @Date: 2022-07-22 10:24:41
 * @LastEditors: wangmiao
 * @LastEditTime: 2022-08-25 13:34:38
 */
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import SetEnvByCommandArg, { getCommandArgv } from "vite-plugin-env-command";
import path from "path";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    SetEnvByCommandArg({
      key: "VITE_ENV",
    }),
  ],
  base: "./",
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "src"),
    },
  },
  build: {
    rollupOptions: {
      output: {
        manualChunks(id) {
          // 将pinia的全局库实例打包进vendor，避免和页面一起打包造成资源重复引入
          if (id.includes("node_modules")) {
            return id
              .toString()
              .split("node_modules/")[1]
              .split("/")[0]
              .toString();
          }
        },
      },
    },
  },
  server: {
    open: true,
    proxy: {
      "/api": {
        target: "https://testripx.iuoooo.com",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ""),
      },
    },
  },
});
